package com.sunday.boot3.user.center.rest.api.impl;

import com.sunday.boot3.user.center.controller.PermissionsController;
import com.sunday.boot3.user.center.pojo.dto.permissions.*;
import com.sunday.boot3.user.center.rest.api.PermissionsApi;
import com.sunday.boot3.user.center.rest.vo.permissions.*;
import com.sunday.common.core.converter.MapperConvert;
import com.sunday.common.core.remoting.rest.annotation.OpenApi;
import com.sunday.common.core.remoting.rest.annotation.VoErrorShowType;
import com.sunday.common.core.remoting.rest.page.PageVO;
import com.sunday.common.core.remoting.rest.response.RestResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

/**
 * @Description: 权限表 Web impl 层
 * @author: zsy
 * @Create: 2024/09/22 16:24:39
 */
@Slf4j
@RestController
@RequestMapping(PermissionsApi.ACCESS_PATH)
@RequiredArgsConstructor
public class PermissionsApiImpl implements PermissionsApi {

    private final PermissionsController permissionsController;

    /**
     * @Description: 新增 权限表 数据
     * @Param: [savePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse save(SavePermissionsReqVO savePermissionsReqVO) {
        return RestResponse.resultReturn(permissionsController.save(MapperConvert.map(savePermissionsReqVO, SavePermissionsReqDTO.class)));
    }

    /**
     * @param saveBatchPermissionsReqVO
     * @return
     * @Description: 权限表 批量权限保存
     */
    @Override
    public RestResponse saveBatch(SaveBatchPermissionsReqVO saveBatchPermissionsReqVO) {
        return RestResponse.resultReturn(permissionsController.saveBatch(MapperConvert.map(saveBatchPermissionsReqVO, SaveBatchPermissionsReqDTO.class)));
    }

    /**
     * @Description: 删除 权限表 数据
     * @Param: [removePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse remove(RemovePermissionsReqVO removePermissionsReqVO) {
        return RestResponse.resultReturn(permissionsController.remove(MapperConvert.map(removePermissionsReqVO, RemovePermissionsReqDTO.class)));
    }

    /**
     * @Description: 修改 权限表 数据
     * @Param: [updatePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    public RestResponse update(UpdatePermissionsReqVO updatePermissionsReqVO) {
        return RestResponse.resultReturn(permissionsController.update(MapperConvert.map(updatePermissionsReqVO, UpdatePermissionsReqDTO.class)));
    }

    /**
     * @Description: 获取 权限表 分页列表数据
     * @Param: [pagePermissionsReqVO]
     * @Return: com.sunday.common.core.remoting.rest.response.RestResponse<com.sunday.common.core.remoting.rest.page.fegin.FeginPageResultVO < com.sunday.boot3.user.center.rest.vo.permissions.PagePermissionsResVO>>
     * @author: zsy
     * @Create: 2024/09/22 16:24:39
     */
    @Override
    @VoErrorShowType(RestResponse.ShowTypeEnum.NOTIFICATION)
    public RestResponse<PageVO<PagePermissionsResVO>> page(PagePermissionsReqVO pagePermissionsReqVO) {
        return RestResponse.convertResultReturn(
                permissionsController.page(MapperConvert.map(pagePermissionsReqVO, PagePermissionsReqDTO.class)),
                body -> PageVO.of(body, PagePermissionsResVO.class));
    }

    /**
     * 全量获取 权限标数据
     * @param
     * @return {@link RestResponse< Collection< ListPermissionsResVO>>}
     */
    @Override
    @OpenApi
    public RestResponse<Collection<ListPermissionsResVO>> list() {
        return RestResponse.convertResultReturn(
                permissionsController.list(),
                body -> MapperConvert.batchMap(body, ListPermissionsResVO.class));
    }

}